<template>
  <el-form ref="form" :model="form" label-width="180px">
    <el-form-item label="会员模式">
      <el-radio-group v-model="form['openMember']">
        <el-radio label="1">开启</el-radio>
        <el-radio label="0">关闭</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="会员折扣(%)">
      <el-input-number v-model="form['memberDiscount']"/>
    </el-form-item>
    <el-form-item label="协议名称" prop="name">
      <el-input v-model="form['protocolTitle']"/>
    </el-form-item>
    <el-form-item label="协议内容" prop="content">
      <ws-editor v-model="form['protocolContent']"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" class="bg-green" @click="submitForm('form')">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    data() {
      return {
        form: {
          openMember: '0'
        }
      }
    },
    mounted() {
      this.loadData()
    },
    methods: {
      loadData() {
        const url = '../videoAdmin/setting/getMemberSetting'
        this.$store.dispatch('GetConnect', { url }).then(res => {
          this.form = res.data;
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const url = '../videoAdmin/setting/saveMemberSetting'
            const data = Object.assign({}, this.form);
            this.$store.dispatch('GetConnect', { url, data }).then(res => {
              this.$message.success(res.msg)
              this.loadData()
            }).catch(e => {
              this.$message.error(e.msg)
            })
          } else {
            this.$message.error('提交失败,请检查必填项')
          }
        })
      }
    }
  }
</script>

<style lang="scss" type="text/scss" scoped>
  @import '../../../../styles/index.scss';
  .el-form {
      max-width: 900px;
  }
</style>
